﻿using System;
using System.Windows.Forms;
using TimeLineDataContract;

namespace TimeLineControl
{
    public static class ScreenUtil
    {
        public static string StringResource(string key)
        {
            return StringResource(key, "en-US");
        }

        public static string StringResource(string key, string defaultLanguage)
        {
            var result = Properties.Resources.ResourceManager.GetString(key);
            if (string.IsNullOrEmpty(result))
            {
                result = Properties.Resources.ResourceManager.GetString(key,
                    new System.Globalization.CultureInfo(
                        defaultLanguage));
            }
            return result;
        }

        public static void SetDockWindows(this Form frm, DockWindows dock, int height, bool fullscreen)
        {
            frm.TopLevel = true;
            frm.TopMost = true; 
            var sr = Screen.PrimaryScreen.Bounds;
            switch (dock)
            {
                case DockWindows.Top:
                    {
                        frm.Top = 0;
                        frm.Left = 0;
                        frm.Width = sr.Width;
                    }
                    break;
                case DockWindows.Bottom:
                    {
                        if (fullscreen)
                        {
                            frm.Top = sr.Height - height;
                        }
                        else
                        {
                            frm.Top = Screen.PrimaryScreen.WorkingArea.Height - height;
                        }
                        frm.Left = 0;
                        frm.Width = sr.Width;
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException("dock");
            }
            frm.ResumeLayout(false);
            frm.PerformLayout();
        }
    }
}
